/*
 * Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.example.ventilation.code.fragment.SysGroup;

import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.SystemClock;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewParent;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.JavascriptInterface;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.FrameLayout;

import androidx.recyclerview.widget.RecyclerView;

import com.example.ventilation.DemoDataProvider;
import com.example.ventilation.code.adapter.WorkingSurfaceDataAdapter;
import com.example.ventilation.code.common.model.GateInfoEntity;
import com.example.ventilation.code.common.model.ReqEntity;
import com.example.ventilation.code.common.model.SysAllTimeDataShowListItem;
import com.example.ventilation.code.common.model.SysItesEntity;
import com.example.ventilation.code.common.model.WindInfoEntity;
import com.example.ventilation.code.common.model.WindowInfoEntity;
import com.example.ventilation.code.utils.GsonTools;
import com.example.ventilation.code.utils.HttpNetUtils;
import com.example.ventilation.code.utils.HttpUtils.PostParams;
import com.example.ventilation.code.utils.HttpUtils.RespListener;
import com.example.ventilation.code.utils.SettingSPUtils;
import com.example.ventilation.code.utils.UrlConstant;
import com.example.ventilation.code.utils.WebSocket.WebSocketManager;
import com.example.ventilation.code.utils.WebSocket.WsManager;
import com.example.ventilation.code.utils.WebSocket.WsStatusListener;
import com.example.ventilation.widget.MPChart.chart.BarChartUtils;
import com.example.ventilation.widget.MPChart.chart.DynamicLineChartManager;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.xuexiang.xpage.annotation.Page;
import com.example.ventilation.R;
import com.example.ventilation.base.BaseWebViewFragment;
import com.example.ventilation.code.utils.Utils;
import com.example.ventilation.code.utils.XToastUtils;
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;
import com.xuexiang.xui.utils.DensityUtils;
import com.xuexiang.xui.utils.WidgetUtils;
import com.xuexiang.xui.widget.dialog.DialogLoader;
import com.xuexiang.xui.widget.textview.badge.Badge;
import com.xuexiang.xui.widget.textview.supertextview.BaseTextView;
import com.xuexiang.xui.widget.textview.supertextview.SuperTextView;

import android.os.Handler;
import android.widget.RadioButton;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;


import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.Response;
import okio.ByteString;

/**
 * @author mashuxing
 * @since 2021-01-26 18:13
 */
@Page(name = "工作面智能管控")
public class WorkingSurfaceFragment extends BaseWebViewFragment implements CompoundButton.OnCheckedChangeListener {

    @BindView(R.id.fl_container)
    FrameLayout flContainer;
    private WsManager wsManager;
    JSONArray monitorList;
    private Long sysID = (long)1;
    private Long modelID = Long.valueOf("1");

    // 工作面参数
    SysItesEntity itesentity;
    private  boolean modelLoadFlag = false;
    private  boolean webOpenFlag = false;
    // 实时监测数据弹框
    private BottomSheetDialog dataShow_dialog;
    // 实时监测数据加载dialog布局view
    private   View dataShow_purchase;
    // 监测数据展示布局
    RecyclerView mDataShowRecyclerView;
    private WorkingSurfaceDataAdapter mDataShowAdapter;
    // 监测数据
    List<SysAllTimeDataShowListItem> datashowList = new ArrayList<SysAllTimeDataShowListItem>();


    // 测风装置柱状图数据
    List<BarEntry> wind_chartvalues = new ArrayList<>();
    // 风窗柱状图数据
    List<BarEntry> window_chartvalues = new ArrayList<>();
    // 风门柱状图数据
    List<BarEntry> gate_chartvalues = new ArrayList<>();
    // 测风装置X轴数据
    String[]  wind_xdata;
    // 风窗X轴数据
    String[]  window_xdata;
    // 风门X轴数据
    String[]  gate_xdata;
    // 图表展示框
    private BottomSheetDialog chartShow_dialog;
    // 图表加载dialog布局view
    private   View chartShow_purchase;
    // 风窗柱状图
    BarChart chartWindow;
    // 测风装置柱状图
    BarChart chartWind;
    // 风门柱状图
    BarChart chartGate;
    // 是否加载测试数据
    private boolean testFlag=true;
    private int valcount = 0;


    // 测风装置折线图数据
    List<Float> wind_m3_linechartvalues = new ArrayList<>();
    private DynamicLineChartManager dynamicLineChart_wind;
    // 风窗折线图数据
    List<Float> window_mpa_linechartvalues = new ArrayList<>();
    private DynamicLineChartManager dynamicLineChart_window;
    // 风门折线图数据
    List<Float> gate_mpa_linechartvalues = new ArrayList<>();
    private DynamicLineChartManager dynamicLineChart_gate;
    // 折线图展示框
    private BottomSheetDialog linechartShow_dialog;
    // 图表加载dialog布局view
    private   View linechartShow_purchase;
    // 风窗折线图
    LineChart linechartWindow;
    // 测风装置折线图
    LineChart linechartWind;
    // 风门折线图
    LineChart linechartGate;
    private List<String> windline_names = new ArrayList<>(); //折线名字集合
    private List<Integer> windline_colors = new ArrayList<>();//折线颜色集合


    private List<String> gateline_names = new ArrayList<>(); //折线名字集合
    private List<Integer> gateline_colors = new ArrayList<>();//折线颜色集合
    private List<String> windowline_names = new ArrayList<>(); //折线名字集合
    private List<Integer> windowline_colors = new ArrayList<>();//折线颜色集合


    // 参数设置展示框
    private BottomSheetDialog paramsShow_dialog;
    // 参数设置加载dialog布局view
    private   View paramsShow_purchase;
    private BottomSheetBehavior<FrameLayout> behavior;

    private SuperTextView controlmMan;
    private SuperTextView controlAuto;
    private SuperTextView TVneedQ;
    private SuperTextView TVnwind_speed;
    private SuperTextView TVngas_density;
    private SuperTextView TVco_density;
    private SuperTextView TVntimeout;
    private SuperTextView TVco_alarm_time;
    private SuperTextView TVsmog_alarm_time;


    private SuperTextView TVneedQ_disabled;
    private SuperTextView TVnwind_speed_disabled;
    private SuperTextView TVngas_density_disabled;
    private SuperTextView TVco_density_disabled;
    private SuperTextView TVntimeout_disabled;
    private SuperTextView TVco_alarm_time_disabled;
    private SuperTextView TVsmog_alarm_time_disabled;
    private int item_type = -1;
    List<RadioButton> radioButtons = new ArrayList<>();
    CompoundButton lastRadioButton;
    private RadioButton RD_SG;
    private RadioButton RD_CO;
    private RadioButton RD_COSG;
    /**
     * 布局的资源id
     *
     * @return
     */
    @Override
    protected int getLayoutId() {
        return R.layout.page_fragment_working_surface;
    }

    /**
     * 初始化控件
     */
    @Override
    protected void initViews() {
        mAgentWeb = Utils.createAgentWeb(this, flContainer, UrlConstant.MODEL_SHOW);

        //注入接口,供JS调用
        mAgentWeb.getJsInterfaceHolder().addJavaObject("Android", new AndroidInterface());

        wsManager = WebSocketManager.getWsManager();
        wsManager.setWsStatusListener(wsStatusListener);
        wsManager.startConnect();
        monitorList = new JSONArray();
        getSysItes();
        // 以特定的风格创建一个dataShow_dialog
        dataShow_dialog = new BottomSheetDialog(getActivity(),R.style.ShowDialog);
        initPurchaseView();

        chartShow_dialog = new BottomSheetDialog(getActivity(),R.style.ShowDialog);
        initChartView();

        linechartShow_dialog = new BottomSheetDialog(getActivity(),R.style.ShowDialog);
        initLineChartView();

        paramsShow_dialog = new BottomSheetDialog(getActivity(),R.style.ShowDialog);
        initParamsView();

    }
    // 显示时，重新发送websocket请求
    public void Show(boolean showflag){
        if(showflag) {
            wsManager.startConnect();
            wsManager.setWsStatusListener(wsStatusListener);
            JSONObject objparam = new JSONObject();
            try {
                objparam.put("type", "deviceStatus");
                objparam.put("obj", monitorList);
            } catch (Exception e) {
            }
            SystemClock.sleep(500);
            wsManager.sendMessage(objparam.toString());
            handler.postDelayed(runnable, 1000);//每秒执行一次runnable.
        }
        else {
            wsManager.stopConnect();
            handler.removeCallbacks(runnable);
        }
    }

    /**
     * websocke 接收实时数据
     */
    private WsStatusListener wsStatusListener = new WsStatusListener() {
        @Override
        public void onOpen(Response response) {
            Log.d("", "WsManager-----onOpen");
        }

        @Override
        public void onMessage(String text) {
            JSONObject data = null;
            String type = "";
            try {
                data = new JSONObject(text);
                if(data.getJSONObject("obj")!= null ){
                    type = data.getJSONObject("obj").getString("deviceType");

                    //测风装置
                    if(type.equals("wind")) {
                        WindInfoEntity.MonitorObj entity = GsonTools.getVo(text, WindInfoEntity.MonitorObj.class);
                        updateWindData(entity);
                    }
                    //风窗
                    else if(type.equals("window")) {
                        WindowInfoEntity.MonitorObj entity = GsonTools.getVo(text, WindowInfoEntity.MonitorObj.class);
                        updateWindowData(entity);
                    }
                    //风门
                    else if(type.equals("gate")) {
                        GateInfoEntity.MonitorObj entity = GsonTools.getVo(text, GateInfoEntity.MonitorObj.class);
                        updateGateData(entity);
                    }
                }
            }
            catch (Exception e){

            }
            Log.d("", "WsManager-----onMessage");
        }
        @Override
        public void onMessage(ByteString bytes) {
            Log.d("", "WsManager-----onMessage");
        }

        @Override
        public void onReconnect() {
            Log.d("", "WsManager-----onReconnect");
        }

        @Override
        public void onClosing(int code, String reason) {
            Log.d("", "WsManager-----onClosing");
        }

        @Override
        public void onClosed(int code, String reason) {
            Log.d("", "WsManager-----onClosed");
        }

        @Override
        public void onFailure(Throwable t, Response response) {
            Log.d("", "WsManager-----onFailure");
        }
    };

    /**
     * 模型信息
     *
     */
    private void getModelInfo() {

        if(!webOpenFlag || modelLoadFlag || itesentity == null || itesentity.getObj() == null)
            return;
        //参数设置
        final PostParams params = new PostParams();
        //登录请求参数设置
        ReqEntity.ModelDetailReq reqobj = new ReqEntity.ModelDetailReq();
        reqobj.setnModelID(itesentity.getObj().getnModelID());
        params.setReqBodyObj(reqobj);
        //登录请求
        HttpNetUtils.getModelDetail(getActivity(), params, new RespListener(getActivity()) {
            @Override
            public void getResp(JSONObject obj) {
                mAgentWeb.getJsAccessEntrace().quickCallJs("showJsonModel",obj.toString());
            }
            @Override
            public void doFailed() {
                XToastUtils.error("获取信息失败，请检查网络！");
            }
        });
    }

    /**
     * 刷新测风装置数据
     *
     */
    private void updateWindData(WindInfoEntity.MonitorObj entity) {
        if (entity != null && entity.getSuccess() && entity.getObj() != null) {

            // 风窗,风门测试数据
            if(37 == entity.getObj().getId() && testFlag){
                updateWindowData(DemoDataProvider.getTestWindowDataEntity());
                Log.e("","getTestWindowDataEntity");
                GateInfoEntity.MonitorObj ooo = DemoDataProvider.getTestGateDataEntity();
                //  风门测试数据，为测试风门
                valcount++;
                if(valcount >20) {
                    ooo.getObj().setbGateStatus("开启");
                    ooo.getObj().setfGateStatus("开启");
                    if(valcount >40)
                        valcount = 0;
                }
                else {
                    ooo.getObj().setbGateStatus("关闭");
                    ooo.getObj().setfGateStatus("关闭");
                }
                updateGateData(ooo);
            }
            String val = "";
            val += entity.getObj().getM3();
            mAgentWeb.getJsAccessEntrace().quickCallJs("setShowData", "wind", entity.getObj().getId().toString(), val);
            for (int i = 0; i < datashowList.size(); i++) {
                if (datashowList.get(i).getId() == entity.getObj().getId()) {
                    datashowList.get(i).setValue1(entity.getObj().getVa().toString());
                    datashowList.get(i).setValue2(entity.getObj().getM3().toString());
                    datashowList.get(i).setValue3(entity.getObj().getmPa().toString());
                    datashowList.get(i).setStrName(entity.getObj().getStrName());
                    mDataShowAdapter.refresh(i,datashowList.get(i));
                    break;
                }
            }
            // 更新柱状图
            if(itesentity!=null && itesentity.getObj().getWspeedId()!=null) {
                for (int i = 0; i < itesentity.getObj().getWspeedId().size(); i++) {
                    if (itesentity.getObj().getWspeedId().get(i) == entity.getObj().getId()) {
                        //设置图表数据源
                        wind_chartvalues.set(i, new BarEntry(i, entity.getObj().getM3().floatValue()));
                        wind_m3_linechartvalues.set(i,entity.getObj().getM3().floatValue());
                        if (wind_xdata[i] == null  || wind_xdata[i].equals("")) {
                            if(entity.getObj().getStrName() !=null) {
                                wind_xdata[i] = entity.getObj().getStrName();
                                BarChartUtils.updateXAxis(chartWind, wind_xdata);
                            }
                        }

                        if(windline_names.get(i).equals("")){
                            if(entity.getObj().getStrName() !=null) {
                                windline_names.set(i, entity.getObj().getStrName());
                                dynamicLineChart_wind.updateLenged(windline_names);
                            }
                        }
                        BarChartUtils.setBarChartData(chartWind,wind_chartvalues);
                    }
                }
            }
        }
    }
    /**
     * 刷新风窗数据
     *
     */
    public void updateWindowData(WindowInfoEntity.MonitorObj entity){
        if (entity != null && entity.getSuccess() && entity.getObj() != null) {
            String val = "";
            val += entity.getObj().getPa();
            mAgentWeb.getJsAccessEntrace().quickCallJs("setShowData", "window", entity.getObj().getId().toString(), val);
            for (int i = 0; i < datashowList.size(); i++) {
                if (datashowList.get(i).getId() == entity.getObj().getId()) {
                    datashowList.get(i).setValue1(entity.getObj().getArea().toString());
                    datashowList.get(i).setValue2(entity.getObj().getmPa().toString());
                    datashowList.get(i).setValue3(entity.getObj().getPa().toString());
                    datashowList.get(i).setStrName(entity.getObj().getStrName());
                    break;
                }
            }
            mDataShowAdapter.refresh(datashowList);
            // 更新柱状图
            if(itesentity!=null && itesentity.getObj().getWindowId()!=null) {
                for (int i = 0; i < itesentity.getObj().getWindowId().size(); i++) {
                    if (itesentity.getObj().getWindowId().get(i) == entity.getObj().getId()) {
                        //设置图表数据源
                        window_chartvalues.set(i, new BarEntry(i, entity.getObj().getmPa().floatValue()));
                        window_mpa_linechartvalues.set(i,entity.getObj().getmPa().floatValue());

                        if (window_xdata[i] == null  || window_xdata[i].equals("")) {
                            if(entity.getObj().getStrName() !=null) {
                                window_xdata[i] = entity.getObj().getStrName();
                                BarChartUtils.updateXAxis(chartWindow, window_xdata);
                            }
                        }
                        if(windowline_names.get(i).equals("")){
                            if(entity.getObj().getStrName() !=null) {
                                windowline_names.set(i, entity.getObj().getStrName());
                                dynamicLineChart_window.updateLenged(windowline_names);
                            }
                        }

                    }
                }
                BarChartUtils.setBarChartData(chartWindow,window_chartvalues);
            }
        }
    }
    /**
     * 刷新风门数据
     *
     */
    public void updateGateData(GateInfoEntity.MonitorObj entity){
        if (entity != null && entity.getSuccess() && entity.getObj() != null) {
            String val = "";
            val += entity.getObj().getPa();
            mAgentWeb.getJsAccessEntrace().quickCallJs("setShowData", "gate", entity.getObj().getId().toString(), val);
            for (int i = 0; i < datashowList.size(); i++) {
                if (datashowList.get(i).getId() == entity.getObj().getId()) {
                    datashowList.get(i).setStrName(entity.getObj().getStrName());
                    if(!datashowList.get(i).getValue1().equals(entity.getObj().getfGateStatus()) || !datashowList.get(i).getValue2().equals(entity.getObj().getbGateStatus())){
                        datashowList.get(i).setValue1(entity.getObj().getfGateStatus());
                        datashowList.get(i).setValue2(entity.getObj().getbGateStatus());
                        mDataShowAdapter.refresh(i,datashowList.get(i));

                        if(entity.getObj().getfGateStatus().equals("开启"))
                        mAgentWeb.getJsAccessEntrace().quickCallJs("setDeviceState","gate",entity.getObj().getId().toString(),UrlConstant.IMG_HOST+"gate_open.png");
                        else
                            mAgentWeb.getJsAccessEntrace().quickCallJs("setDeviceState","gate",entity.getObj().getId().toString(),UrlConstant.IMG_HOST+"gate_close.png");
                    }
                    break;
                }
            }

            // 更新柱状图
            if(itesentity!=null&& itesentity.getObj().getGateId()!=null) {
                for (int i = 0; i < itesentity.getObj().getGateId().size(); i++) {
                    if (itesentity.getObj().getGateId().get(i) == entity.getObj().getId()) {
                        //设置图表数据源
                        gate_chartvalues.set(i, new BarEntry(i, entity.getObj().getmPa().floatValue()));
                        gate_mpa_linechartvalues.set(i,entity.getObj().getmPa().floatValue());

                        if (gate_xdata[i] == null  || gate_xdata[i].equals("")) {
                            if(entity.getObj().getStrName() !=null) {
                                gate_xdata[i] = entity.getObj().getStrName();
                                BarChartUtils.updateXAxis(chartGate, gate_xdata);
                            }
                        }

                        if(gateline_names.get(i).equals("")){
                            if(entity.getObj().getStrName() !=null) {
                                gateline_names.set(i, entity.getObj().getStrName());
                                dynamicLineChart_gate.updateLenged(gateline_names);
                            }
                        }
                    }
                }
                BarChartUtils.setBarChartData(chartGate,gate_chartvalues);
            }
        }
    }
    /**
     * 智能管控系统参数信息
     *
     */
    private void getSysItes() {

        //参数设置
        final PostParams params = new PostParams();
        //登录请求参数设置
        ReqEntity.SysItesReq reqobj = new ReqEntity.SysItesReq();
        reqobj.setId(Long.valueOf(sysID));
        params.setReqBodyObj(reqobj);
        //登录请求
        HttpNetUtils.getSysItes(getActivity(), params, new RespListener(getActivity()) {
            @Override
            public void getResp(JSONObject obj) {
                //返回数据
                itesentity = GsonTools.getVo(obj.toString(), SysItesEntity.class);
                //成功
                if (itesentity.getSuccess()) {

                    if(itesentity.getObj().getType() !=null && itesentity.getObj().getType().equals("0")){
                        controlAuto.setCheckBoxChecked(true);
                        controlmMan.setCheckBoxChecked(false);
                        item_type = 0;
                        setTypeShow(item_type);
                    }
                    else {
                        controlAuto.setCheckBoxChecked(false);
                        controlmMan.setCheckBoxChecked(true);
                        item_type = 1;
                        setTypeShow(item_type);
                    }
                    if(itesentity.getObj().getSensorType() != null && itesentity.getObj().getSensorType().equals("CO")){
                        RD_CO.setChecked(true);
                        lastRadioButton = RD_CO;
                    }
                    else if(itesentity.getObj().getSensorType() != null && itesentity.getObj().getSensorType().equals("SG")){
                        RD_SG.setChecked(true);
                        lastRadioButton = RD_SG;
                    }
                    else if(itesentity.getObj().getSensorType() != null && itesentity.getObj().getSensorType().equals("ALL")){
                        RD_COSG.setChecked(true);
                        lastRadioButton = RD_COSG;
                    }
                    TVneedQ.setCenterEditString(Utils.getS_Double(itesentity.getObj().getNeedQ()));
                    TVnwind_speed.setCenterEditString(Utils.getS_Double(itesentity.getObj().getWind_speed()));
                    TVngas_density.setCenterEditString(Utils.getS_Double(itesentity.getObj().getGas_density()));
                    TVco_density.setCenterEditString(Utils.getS_Double(itesentity.getObj().getCo_density()));
                    TVntimeout.setCenterEditString(Utils.getS_Integer(itesentity.getObj().getTimeout()));
                    TVco_alarm_time.setCenterEditString(Utils.getS_Integer(itesentity.getObj().getCo_alarm_time()));
                    TVsmog_alarm_time.setCenterEditString(Utils.getS_Integer(itesentity.getObj().getSmog_alarm_time()));


                    TVneedQ_disabled.setRightString(Utils.getS_Double(itesentity.getObj().getNeedQ()));
                    TVnwind_speed_disabled.setRightString(Utils.getS_Double(itesentity.getObj().getWind_speed()));
                    TVngas_density_disabled.setRightString(Utils.getS_Double(itesentity.getObj().getGas_density()));
                    TVco_density_disabled.setRightString(Utils.getS_Double(itesentity.getObj().getCo_density()));
                    TVntimeout_disabled.setRightString(Utils.getS_Integer(itesentity.getObj().getTimeout()));
                    TVco_alarm_time_disabled.setRightString(Utils.getS_Integer(itesentity.getObj().getCo_alarm_time()));
                    TVsmog_alarm_time_disabled.setRightString(Utils.getS_Integer(itesentity.getObj().getSmog_alarm_time()));
//                    TVsensorType.setCenterEditString(Utils.getS_Double(itesentity.getObj().getSensorType()));
                    monitorList = new JSONArray();
                    // 添加设备ID到monitorList，开启实时监控参数
                    if(itesentity.getObj().getWspeedId()!=null) {
                        for (int i = 0; i < itesentity.getObj().getWspeedId().size(); i++) {
                            if (itesentity.getObj().getWspeedId().get(i) != null)
                                monitorList.put(itesentity.getObj().getWspeedId().get(i));
                        }
                    }
                    if(itesentity.getObj().getWindowId()!=null) {
                        for (int i = 0; i < itesentity.getObj().getWindowId().size(); i++) {
                            if (itesentity.getObj().getWindowId().get(i) != null)
                                monitorList.put(itesentity.getObj().getWindowId().get(i));
                        }
                    }
                    if(itesentity.getObj().getGateId()!=null) {
                        for (int i = 0; i < itesentity.getObj().getGateId().size(); i++) {
                            if (itesentity.getObj().getGateId().get(i) != null)
                                monitorList.put(itesentity.getObj().getGateId().get(i));
                        }
                    }
                    //模型ID
                    modelID = itesentity.getObj().getnModelID();
                    // 发送请求，获取监测数据
                    JSONObject objparam = new JSONObject();
                    try {
                        objparam.put("type","deviceStatus");
                        objparam.put("obj",monitorList);
                    }
                    catch (Exception e){
                    }
                    wsManager.sendMessage(objparam.toString());
                    initShowData();
                    mDataShowAdapter.refresh(datashowList);
                    handler.postDelayed(runnable, 1000);//每秒执行一次runnable.
                    getModelInfo();

                } else {
                    XToastUtils.error("获取信息失败");
                }
            }
            @Override
            public void doFailed() {
                XToastUtils.success("获取信息失败，请检查网络！");
            }
        });
    }
    /**
     * 更新智能管控系统参数信息
     *
     */
    private void updateSysItes(String value ) {
        //参数设置
        final PostParams params = new PostParams();
        //登录请求参数设置
        ReqEntity.editSysItesTypeReq reqobj = new ReqEntity.editSysItesTypeReq();
        reqobj.setId(Long.valueOf(sysID));
        reqobj.setType(String.valueOf(value));
        params.setReqBodyObj(reqobj);
        //登录请求
        HttpNetUtils.updateSysItes(getActivity(), params, new RespListener(getActivity()) {
            @Override
            public void getResp(JSONObject obj) {
                //返回数据
                itesentity = GsonTools.getVo(obj.toString(), SysItesEntity.class);
                //成功
                try {
                    if (obj.getBoolean("success")) {
                        item_type = Integer.valueOf(value);
                        XToastUtils.success("设置成功");
                    }else {
                        XToastUtils.error("设置失败");
                    }

                    if (item_type == 0) {
                        controlmMan.setCheckBoxChecked(false);
                        controlAuto.setCheckBoxChecked(true);
                        setTypeShow(item_type);
                    } else {
                        controlmMan.setCheckBoxChecked(true);
                        controlAuto.setCheckBoxChecked(false);
                        setTypeShow(item_type);
                    }
                }
                catch(Exception e){

                }
            }
            @Override
            public void doFailed() {
                XToastUtils.success("获取信息失败，请检查网络！");
            }
        });
    }
    /**
     * 更新智能管控系统参数信息--设置需风量
     *
     */
    private void updateSysItesNeedQ(Double value ) {
        //参数设置
        final PostParams params = new PostParams();
        //登录请求参数设置
        ReqEntity.editSysItesNeedQReq reqobj = new ReqEntity.editSysItesNeedQReq();
        reqobj.setId(Long.valueOf(sysID));
        reqobj.setNeedQ(value);
        params.setReqBodyObj(reqobj);
        //登录请求
        HttpNetUtils.updateSysItes(getActivity(), params, new RespListener(getActivity()) {
            @Override
            public void getResp(JSONObject obj) {
                //返回数据
                itesentity = GsonTools.getVo(obj.toString(), SysItesEntity.class);
                //成功
                try {
                    if (obj.getBoolean("success")) {
                        JSONObject o = new JSONObject();
                        JSONObject s_o = new JSONObject();
                        JSONObject s_o1 = new JSONObject();
                        s_o1.put("type","1");
                        s_o1.put("id",Long.valueOf(sysID));
                        s_o.put("type","windControlSystem");
                        s_o.put("obj",s_o1);
                        s_o.put("type","'windControlSystem'");
                        o.put("type","controlFanSystem");
                        o.put("obj",s_o);
                        // 发送websocket请求
                        wsManager.sendMessage(o.toString());
                        XToastUtils.success("设置成功");
                    }else {
                        XToastUtils.error("设置失败");
                    }
                }
                catch(Exception e){

                }
            }
            @Override
            public void doFailed() {
                XToastUtils.success("获取信息失败，请检查网络！");
            }
        });
    }
    /**
     * 更新智能管控系统参数信息--j决策参数
     *
     */
    private void updateSysItesParam(PostParams params ) {
        //登录请求
        HttpNetUtils.updateSysItes(getActivity(), params, new RespListener(getActivity()) {
            @Override
            public void getResp(JSONObject obj) {
                //返回数据
                itesentity = GsonTools.getVo(obj.toString(), SysItesEntity.class);
                //成功
                try {
                    if (obj.getBoolean("success")) {
                        XToastUtils.success("设置成功");
                    }else {
                        XToastUtils.error("设置失败");
                    }
                }
                catch(Exception e){

                }
            }
            @Override
            public void doFailed() {
                XToastUtils.success("获取信息失败，请检查网络！");
            }
        });
    }
    /**
     * 注入到JS里的对象接口
     */
    public class AndroidInterface {

        @JavascriptInterface
        public void callAndroid(final String msg) {
            webOpenFlag = true;
            getModelInfo();
        }

        @JavascriptInterface
        public void callDeviceClick(final String type,final String data) {
            XToastUtils.success(data);
        }
    }
    @Override
    public void onDestroy() {
        wsManager.stopConnect();
        handler.removeCallbacks(runnable);
        super.onDestroy();
    }
    /**
     * 底部弹框参数设置
     */
    @OnClick(R.id.ites_set)
    void setItes(View v) {
        showParamsView();
    }
    /**
     * 底部弹框显示图表 柱状图
     */
    @OnClick(R.id.charts_show)
    void showChart2(View v) {
        showChartView();
    }
    /**
     * 底部弹框显示图表 折线图
     */
    @OnClick(R.id.charts_show1)
    void showChart1(View v) {
        showLineChartView();
    }
    /**
     * 底部弹框显示实时数据
     */
    @OnClick(R.id.data_show)
    void dataShow(View v) {
        showPurchaseView();
    }
    // 底部弹窗显示实时数据
    public void initPurchaseView() {
        // 加载dialog布局view
        dataShow_purchase = LayoutInflater.from(getActivity()).inflate(R.layout.page_dialog_workingsurface_datashow, null);
        initPurchaseViews(dataShow_purchase,dataShow_dialog);
        // 设置外部点击 取消dialog

        dataShow_dialog.setCancelable(true);
        dataShow_dialog.setCanceledOnTouchOutside(true);

        // 获得窗体对象
        Window window = dataShow_dialog.getWindow();
        // 设置窗体的对齐方式
        window.setGravity(Gravity.BOTTOM);
        // 设置窗体动画
        window.setWindowAnimations(R.style.AnimBottom);
        // 设置窗体的padding
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
        dataShow_dialog.setContentView(dataShow_purchase);

        mDataShowRecyclerView = dataShow_purchase.findViewById(R.id.recyclerView);
        WidgetUtils.initGridRecyclerView(mDataShowRecyclerView,2, DensityUtils.dp2px(2));

        mDataShowRecyclerView.setAdapter(mDataShowAdapter = new WorkingSurfaceDataAdapter());

        mDataShowAdapter.setOnItemClickListener(new RecyclerViewHolder.OnItemClickListener<SysAllTimeDataShowListItem>() {
            @Override
            public void onItemClick(View itemView, SysAllTimeDataShowListItem item, int position) {
            }
        });
    }

    // 底部弹窗实时数据显示初始化
    private void initShowData(){
        // 添加设备监测字段，
        if(itesentity.getObj().getGateId()!=null) {
            chartGate.getXAxis().setLabelCount(itesentity.getObj().getGateId().size());
            gate_xdata = new String[itesentity.getObj().getGateId().size()];
            for (int i = 0; i < itesentity.getObj().getGateId().size(); i++) {
                gate_xdata[i] = "";
                SysAllTimeDataShowListItem item = new SysAllTimeDataShowListItem();
                item.setId(itesentity.getObj().getGateId().get(i));
                item.setRotation(0);
                item.setType("gate");
                item.setShow1("前门状态");
                item.setShow2("后门状态");
                item.setValue1("");
                item.setValue2("");
                item.setStrName("");
                datashowList.add(item);
                gate_chartvalues.add(new BarEntry(i, 0));
                gate_mpa_linechartvalues.add((float) 0);
                gateline_names.add("");
                gateline_colors.add(Utils.CHART_COLORS[i]);
            }
        }
        if(itesentity.getObj().getWindowId()!=null) {
            chartWindow.getXAxis().setLabelCount(itesentity.getObj().getWindowId().size());
            window_xdata = new String[itesentity.getObj().getWindowId().size()];
            for (int i = 0; i < itesentity.getObj().getWindowId().size(); i++) {
                window_xdata[i] = "";
                SysAllTimeDataShowListItem item = new SysAllTimeDataShowListItem();
                item.setId(itesentity.getObj().getWindowId().get(i));
                item.setRotation(0);
                item.setType("window");
                item.setShow1("风窗面积");
                item.setShow2("气源压力");
                item.setShow3("压差");
                item.setStrName("");
                datashowList.add(item);
                window_chartvalues.add(new BarEntry(i, 0));
                window_mpa_linechartvalues.add((float) 0);
                windowline_names.add("");
                windowline_colors.add(Utils.CHART_COLORS[i]);
            }
        }
        if(itesentity.getObj().getWspeedId()!=null) {
            chartWind.getXAxis().setLabelCount(itesentity.getObj().getWspeedId().size());
            wind_xdata = new String[itesentity.getObj().getWspeedId().size()];
            for (int i = 0; i < itesentity.getObj().getWspeedId().size(); i++) {
                wind_xdata[i] = "";
                SysAllTimeDataShowListItem item = new SysAllTimeDataShowListItem();
                item.setId(itesentity.getObj().getWspeedId().get(i));
                item.setRotation(0);
                item.setType("wind");
                item.setShow1("风速");
                item.setShow2("风量");
                item.setShow3("气源压力");
                item.setStrName("");
                datashowList.add(item);
                wind_chartvalues.add(new BarEntry(i, 0));
                wind_m3_linechartvalues.add((float) 0);
                windline_names.add("");
                windline_colors.add(Utils.CHART_COLORS[i]);

            }
        }





        dynamicLineChart_wind = new DynamicLineChartManager(linechartWind, windline_names, windline_colors);
        dynamicLineChart_wind.setYAxis(5000, 0, 5);

        dynamicLineChart_window = new DynamicLineChartManager(linechartWindow, windowline_names, windowline_colors);
        dynamicLineChart_window.setYAxis(15, 0, 5);

        dynamicLineChart_gate = new DynamicLineChartManager(linechartGate, gateline_names, gateline_colors);
        dynamicLineChart_gate.setYAxis(15, 0, 5);
    }

    // 显示弹框
    public void showPurchaseView() {
        // 加载dialog布局view
        dataShow_dialog.show();

    }

    // 弹框点击事件
    private void initPurchaseViews(View purchase, final Dialog dialog) {
        purchase.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        purchase.findViewById(R.id.llInner).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
        purchase.findViewById(R.id.rootView).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
    }
    // 底部弹窗显示柱状图数据
    public void initChartView() {
        // 加载dialog布局view
        chartShow_purchase = LayoutInflater.from(getActivity()).inflate(R.layout.page_dialog_workingsurface_chartshow, null);
        initChartViews(chartShow_purchase,chartShow_dialog);
        // 设置外部点击 取消dialog

        chartShow_dialog.setCancelable(true);
        chartShow_dialog.setCanceledOnTouchOutside(true);

        // 获得窗体对象
        Window window = chartShow_dialog.getWindow();
        // 设置窗体的对齐方式
        window.setGravity(Gravity.BOTTOM);
        // 设置窗体动画
        window.setWindowAnimations(R.style.AnimBottom);
        // 设置窗体的padding
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
        chartShow_dialog.setContentView(chartShow_purchase);

        chartWind = chartShow_purchase.findViewById(R.id.chart_wind);
        chartGate = chartShow_purchase.findViewById(R.id.chart_gate);
        chartWindow = chartShow_purchase.findViewById(R.id.chart_window);
        initShowChart_Wind();
        initShowChart_Window();
        initShowChart_Gate();
    }

    // 测风装置底部弹窗图表数据显示初始化
    private void initShowChart_Wind() {
        BarChartUtils.BarChartUtils(chartWind);
        BarChartUtils.setYValue(chartWind,3000);
        BarChartUtils.setY_RightVisible(chartWind,false);
        BarChartUtils.setLabelRotationAngle(chartWind,-15);

    }
    // 风窗底部弹窗图表数据显示初始化
    private void initShowChart_Window() {
        BarChartUtils.BarChartUtils(chartWindow);
        BarChartUtils.setYValue(chartWindow,15);
        BarChartUtils.setY_RightVisible(chartWindow,false);
        BarChartUtils.setLabelRotationAngle(chartWindow,-15);
    }
    // 风门底部弹窗图表数据显示初始化
    private void initShowChart_Gate() {
        BarChartUtils.BarChartUtils(chartGate);
        BarChartUtils.setYValue(chartGate,15);
        BarChartUtils.setY_RightVisible(chartGate,false);
        BarChartUtils.setLabelRotationAngle(chartGate,-15);
    }
    // 显示弹框
    public void showChartView() {
        // 加载dialog布局view
        chartShow_dialog.show();

    }

    // 弹框点击事件
    private void initChartViews(View purchase, final Dialog dialog) {
        purchase.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        purchase.findViewById(R.id.llInner).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
        purchase.findViewById(R.id.rootView).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
    }



    // 底部弹窗显示折线图数据
    public void initLineChartView() {
        // 加载dialog布局view
        linechartShow_purchase = LayoutInflater.from(getActivity()).inflate(R.layout.page_dialog_workingsurface_linechartshow, null);
        initLineChartViews(linechartShow_purchase,linechartShow_dialog);
        // 设置外部点击 取消dialog

        linechartShow_dialog.setCancelable(true);
        linechartShow_dialog.setCanceledOnTouchOutside(true);

        // 获得窗体对象
        Window window = linechartShow_dialog.getWindow();
        // 设置窗体的对齐方式
        window.setGravity(Gravity.BOTTOM);
        // 设置窗体动画
        window.setWindowAnimations(R.style.AnimBottom);
        // 设置窗体的padding
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
        linechartShow_dialog.setContentView(linechartShow_purchase);

        linechartWind = linechartShow_purchase.findViewById(R.id.linechart_wind);
        linechartGate = linechartShow_purchase.findViewById(R.id.linechart_gate);
        linechartWindow = linechartShow_purchase.findViewById(R.id.linechart_window);
    }

    // 显示弹框
    public void showLineChartView() {
        // 加载dialog布局view
        linechartShow_dialog.show();

    }

    // 弹框点击事件
    private void initLineChartViews(View purchase, final Dialog dialog) {
        purchase.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        purchase.findViewById(R.id.llInner).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
        purchase.findViewById(R.id.rootView).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
    }



    // 根据控制类型，设置参数可用状态
    public void setTypeShow(int type){
        if(type == 1){
            TVneedQ.setVisibility(View.VISIBLE);
            TVneedQ_disabled.setVisibility(View.GONE);
            paramsShow_purchase.findViewById(R.id.bt_set_needQ).setEnabled(true);
            RD_SG.setEnabled(true);
            RD_CO.setEnabled(true);
            RD_COSG.setEnabled(true);

            TVnwind_speed.setVisibility(View.GONE);
            TVnwind_speed_disabled.setRightString(TVnwind_speed.getCenterEditValue());
            TVnwind_speed_disabled.setVisibility(View.VISIBLE);

            TVngas_density.setVisibility(View.GONE);
            TVngas_density_disabled.setRightString(TVngas_density.getCenterEditValue());
            TVngas_density_disabled.setVisibility(View.VISIBLE);

            TVco_density.setVisibility(View.GONE);
            TVco_density_disabled.setRightString(TVco_density.getCenterEditValue());
            TVco_density_disabled.setVisibility(View.VISIBLE);

            TVntimeout.setVisibility(View.GONE);
            TVntimeout_disabled.setRightString(TVntimeout.getCenterEditValue());
            TVntimeout_disabled.setVisibility(View.VISIBLE);

            TVco_alarm_time.setVisibility(View.GONE);
            TVco_alarm_time_disabled.setRightString(TVco_alarm_time.getCenterEditValue());
            TVco_alarm_time_disabled.setVisibility(View.VISIBLE);

            TVsmog_alarm_time.setVisibility(View.GONE);
            TVsmog_alarm_time_disabled.setRightString(TVsmog_alarm_time.getCenterEditValue());
            TVsmog_alarm_time_disabled.setVisibility(View.VISIBLE);
        }
        else {
            TVneedQ.setVisibility(View.GONE);
            TVneedQ_disabled.setRightString(TVneedQ.getCenterEditValue());
            TVneedQ_disabled.setVisibility(View.VISIBLE);
            paramsShow_purchase.findViewById(R.id.bt_set_needQ).setEnabled(false);


            TVnwind_speed.setVisibility(View.VISIBLE);
            TVnwind_speed_disabled.setVisibility(View.GONE);

            TVngas_density.setVisibility(View.VISIBLE);
            TVngas_density_disabled.setVisibility(View.GONE);

            TVco_density.setVisibility(View.VISIBLE);
            TVco_density_disabled.setVisibility(View.GONE);

            TVntimeout.setVisibility(View.VISIBLE);
            TVntimeout_disabled.setVisibility(View.GONE);

            TVco_alarm_time.setVisibility(View.VISIBLE);
            TVco_alarm_time_disabled.setVisibility(View.GONE);

            TVsmog_alarm_time.setVisibility(View.VISIBLE);
            TVsmog_alarm_time_disabled.setVisibility(View.GONE);

            RD_SG.setEnabled(false);
            RD_CO.setEnabled(false);
            RD_COSG.setEnabled(false);
        }
    }

    // 底部弹窗显示参数设置
    public void initParamsView() {
        // 加载dialog布局view
        paramsShow_purchase = LayoutInflater.from(getActivity()).inflate(R.layout.page_dialog_workingsurface_paramsshow, null);
        initParamsViews(paramsShow_purchase,paramsShow_dialog);
        // 设置外部点击 取消dialog

        paramsShow_dialog.setCancelable(true);
        paramsShow_dialog.setCanceledOnTouchOutside(true);

        // 获得窗体对象
        Window window = paramsShow_dialog.getWindow();
        // 设置窗体的对齐方式
        window.setGravity(Gravity.BOTTOM);
        // 设置窗体动画
        window.setWindowAnimations(R.style.AnimBottom);
        // 设置窗体的padding
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
        paramsShow_dialog.setContentView(paramsShow_purchase);


        ViewParent parent = paramsShow_purchase.getParent();

        behavior = BottomSheetBehavior.from(((FrameLayout) parent));
        
        controlmMan = paramsShow_purchase.findViewById(R.id.control_man);
        controlAuto = paramsShow_purchase.findViewById(R.id.control_auto);
        TVneedQ = paramsShow_purchase.findViewById(R.id.tv_needQ);
        TVnwind_speed = paramsShow_purchase.findViewById(R.id.tv_wind_speed);
        TVngas_density = paramsShow_purchase.findViewById(R.id.tv_gas_density);
        TVco_density = paramsShow_purchase.findViewById(R.id.tv_co_density);
        TVntimeout = paramsShow_purchase.findViewById(R.id.tv_timeout);
        TVco_alarm_time = paramsShow_purchase.findViewById(R.id.tv_co_alarm_time);
        TVsmog_alarm_time = paramsShow_purchase.findViewById(R.id.tv_smog_alarm_time);


        TVneedQ_disabled = paramsShow_purchase.findViewById(R.id.tv_needQ_disabled);
        TVnwind_speed_disabled = paramsShow_purchase.findViewById(R.id.tv_wind_speed_disabled);
        TVngas_density_disabled = paramsShow_purchase.findViewById(R.id.tv_gas_density_disabled);
        TVco_density_disabled = paramsShow_purchase.findViewById(R.id.tv_co_density_disabled);
        TVntimeout_disabled = paramsShow_purchase.findViewById(R.id.tv_timeout_disabled);
        TVco_alarm_time_disabled = paramsShow_purchase.findViewById(R.id.tv_co_alarm_time_disabled);
        TVsmog_alarm_time_disabled = paramsShow_purchase.findViewById(R.id.tv_smog_alarm_time_disabled);

        RD_SG = (RadioButton)  paramsShow_purchase.findViewById(R.id.rb_sg);
        RD_CO = (RadioButton)  paramsShow_purchase.findViewById(R.id.rb_co);
        RD_COSG = (RadioButton)  paramsShow_purchase.findViewById(R.id.rb_cosg);
        radioButtons.add(RD_SG);
        radioButtons.add(RD_CO);
        radioButtons.add(RD_COSG);
        for (RadioButton rb : radioButtons) {
            rb.setOnCheckedChangeListener(this);
        }
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (!isChecked) {
            return;
        }
        if (lastRadioButton != null) {
            lastRadioButton.setChecked(false);
        }
        lastRadioButton = buttonView;
            switch (buttonView.getId()) {
                case R.id.rb_co:
//                    badge.setBadgeGravity(Gravity.START | Gravity.TOP);
                    break;
                case R.id.rb_sg:
//                    badge.setBadgeGravity(Gravity.START | Gravity.BOTTOM);
                    break;
                case R.id.rb_cosg:
//                    badge.setBadgeGravity(Gravity.END | Gravity.TOP);
                    break;
        }
    }
    // 显示弹框
    public void showParamsView() {
        // 加载dialog布局view
//        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
        paramsShow_dialog.show();

    }
    // 弹框点击事件
    private void initParamsViews(View purchase, final Dialog dialog) {
        ((SuperTextView)purchase.findViewById(R.id.control_auto)).setCheckBoxCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    if(item_type == 1){
                        DialogLoader.getInstance().showConfirmDialog(
                                getActivity(),"确定要切换到智能决策自动控制工作面风量吗？",
                                getString(R.string.lab_yes),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        updateSysItes("0");
                                    }
                                },
                                getString(R.string.lab_no),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        ((SuperTextView)purchase.findViewById(R.id.control_auto)).setCheckBoxChecked(false);
                                    }
                                }
                        );
                    }
                }
                else{
                    ((SuperTextView)purchase.findViewById(R.id.control_auto)).setCheckBoxChecked(true);
                }
            }
        });
        ((SuperTextView)purchase.findViewById(R.id.control_man)).setCheckBoxCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    if(item_type == 0){
                        DialogLoader.getInstance().showConfirmDialog(
                                getActivity(),"确定要切换到人工控制工作面风量吗？",
                                getString(R.string.lab_yes),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        updateSysItes("1");
                                    }
                                },
                                getString(R.string.lab_no),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        ((SuperTextView)purchase.findViewById(R.id.control_man)).setCheckBoxChecked(false);
                                    }
                                }
                        );
                    }
                }
                else
                    ((SuperTextView)purchase.findViewById(R.id.control_man)).setCheckBoxChecked(true);
            }
        });
        purchase.findViewById(R.id.bt_inverted).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
        purchase.findViewById(R.id.bt_normal).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
        purchase.findViewById(R.id.bt_set_needQ).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateSysItesNeedQ(Utils.getD_String(TVneedQ.getCenterEditValue()));
            }
        });
        purchase.findViewById(R.id.bt_set_param).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //参数设置
                final PostParams params = new PostParams();
                //登录请求参数设置
                ReqEntity.editSysItesParamReq reqobj = new ReqEntity.editSysItesParamReq();
                reqobj.setId(Long.valueOf(sysID));
                if(item_type == 0) {
                    reqobj.setCo_density(Utils.getD_String(TVco_density.getCenterEditValue()));
                    reqobj.setGas_density(Utils.getD_String(TVngas_density.getCenterEditValue()));
                    reqobj.setWind_speed(Utils.getD_String(TVnwind_speed.getCenterEditValue()));
                    reqobj.setCo_alarm_time(Utils.getI_String(TVco_alarm_time.getCenterEditValue()));
                    reqobj.setSmog_alarm_time(Utils.getI_String(TVsmog_alarm_time.getCenterEditValue()));
                    reqobj.setTimeout(Utils.getI_String(TVntimeout.getCenterEditValue()));
                }
                else if(item_type == 1) {
                    if (RD_CO.isChecked())
                        reqobj.setSensorType("CO");
                    else if (RD_SG.isChecked())
                        reqobj.setSensorType("SG");
                    else if (RD_COSG.isChecked())
                        reqobj.setSensorType("ALL");
                }
                params.setReqBodyObj(reqobj);
                updateSysItesParam(params);
            }
        });
        purchase.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        purchase.findViewById(R.id.llInner).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
        purchase.findViewById(R.id.rootView).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
    }


    Handler handler=new Handler();
    Runnable runnable=new Runnable() {
        @Override
        public void run() {
            if(wind_m3_linechartvalues.size()>0)
            dynamicLineChart_wind.addEntry(wind_m3_linechartvalues);
            if(window_mpa_linechartvalues.size()>0)
            dynamicLineChart_window.addEntry(window_mpa_linechartvalues);
            if(gate_mpa_linechartvalues.size()>0)
            dynamicLineChart_gate.addEntry(gate_mpa_linechartvalues);
            handler.postDelayed(this, 1000);
        }
    };
}
